package com.hg.miaosha.product;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @Author: skh
 * @Date: 2019/10/16 15:12
 * @Description:
 */
public interface ProductDao extends BaseMapper<ProductDO> {

    @Select("select * from tb_product where product_id=#{productId}")
    ProductDO getProductByProductId(Integer productId);

    //通过stock>0防止超卖
    @Update("update tb_product set stock = stock-1 where product_id=#{productId} and stock>0")
    Integer reduceStock(@Param("productId") Integer productId, @Param("amount") Integer amount);
}
